﻿/**************************************************************
* Copyright (C) 2022 www.eipflow.com 孙泽伟版权所有(盗版必究)
*
* 作者: 孙泽伟(QQ 1039318332)
* 创建时间: 2022/01/12 22:40:15
* 文件名: 
* 描述: 
* 
* 修改历史
* 修改人：
* 时间：
* 修改说明：
*
**************************************************************/
using EIP.System.Models.Dtos.WorkSheet;

namespace EIP.System.Controller
{
    /// <summary>
    /// 工作表控制器
    /// </summary>
    public class WorkSheetController : BaseSystemController
    {
        #region 构造函数

        private readonly ISystemWorkSheetLogic _systemWorkSheetLogic;
        private readonly ISystemFileLogic _systemFileLogic;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="systemWorkSheetLogic"></param>
        /// <param name="systemFileLogic"></param>
        public WorkSheetController(ISystemWorkSheetLogic systemWorkSheetLogic,
            ISystemFileLogic systemFileLogic)
        {
            _systemWorkSheetLogic = systemWorkSheetLogic;
            _systemFileLogic = systemFileLogic;
        }

        #endregion

        #region 表操作
       
        /// <summary>
        /// 表是否存在
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("应用数据库-方法-列表-获取对应表列信息", RemarkFrom.System)]
        [Route("/system/worksheet/table/exist")]
        public async Task<ActionResult> TableExist(SystemWorkSheetTableExistInput input)
        {
            return Ok(await _systemWorkSheetLogic.TableExist(input));
        }

        /// <summary>
        /// 创建表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("表单维护-方法-创建表", RemarkFrom.System)]
        [Route("/system/worksheet/table")]
        public ActionResult Table(SystemWorkSheetTableInput input)
        {
            return Ok(_systemWorkSheetLogic.Table(input));
        }
        /// <summary>
        /// 修改表别名称
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("表单维护-方法-修改表别名称", RemarkFrom.System)]
        [Route("/system/worksheet/table/rename")]
        public ActionResult TableRename(SystemWorkSheetTableInput input)
        {
            return Ok(_systemWorkSheetLogic.TableRename(input));
        }
        /// <summary>
        /// 修改表字段
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("表单维护-方法-修改表字段", RemarkFrom.System)]
        [Route("/system/worksheet/table/field")]
        public async Task<ActionResult> TableField(SystemWorkSheetTableFieldInput input)
        {
            return Ok(await _systemWorkSheetLogic.TableField(input));
        }
        /// <summary>
        /// 删除表字段
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("表单维护-方法-删除表字段", RemarkFrom.System)]
        [Route("/system/worksheet/table/field/delete")]
        public async Task<ActionResult> TableFieldDelete(SystemWorkSheetTableFieldInput input)
        {
            return Ok(await _systemWorkSheetLogic.TableFieldDelete(input));
        }
        #endregion

        #region 数据操作

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="input">信息</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-新增/编辑-保存", RemarkFrom.System, true)]
        [Route("/system/worksheet")]
        public async Task<ActionResult> Save(SystemWorkSheetSaveInput input)
        {
            input.UserId = CurrentUser.UserId;
            input.UserCode = CurrentUser.Code;
            input.UserName = CurrentUser.Name;
            input.OrganizationName = CurrentUser.OrganizationName;
            if (CurrentUser.OrganizationId != null) input.OrganizationId = (Guid)CurrentUser.OrganizationId;
            var result = await _systemWorkSheetLogic.Save(input);
            return Ok(result);
        }

        /// <summary>
        /// 根据主键获取信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-根据主键获取信息", RemarkFrom.System)]
        [Route("/system/worksheet/byid")]
        public async Task<ActionResult> FindById(SystemWorkSheetFindByIdInput input)
        {
            return Ok(await _systemWorkSheetLogic.FindById(input));
        }
        /// <summary>
        /// 逻辑删除业务数据
        /// </summary>
        /// <param name="input">Id</param>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-删除", RemarkFrom.System, true)]
        [Route("/system/worksheet/delete")]
        public async Task<ActionResult> Delete(SystemWorkSheetDeleteInput input)
        {
            return Ok(await _systemWorkSheetLogic.Delete(input));
        }

        /// <summary>
        /// 物理删除业务数据
        /// </summary>
        /// <param name="input">Id</param>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-删除", RemarkFrom.System, true)]
        [Route("/system/worksheet/delete/physics")]
        public async Task<ActionResult> DeletePhysics(SystemWorkSheetDeleteInput input)
        {
            return Ok(await _systemWorkSheetLogic.DeletePhysics(input));
        }
        /// <summary>
        /// 物理删除业务数据
        /// </summary>
        /// <param name="input">Id</param>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-删除", RemarkFrom.System, true)]
        [Route("/system/worksheet/delete/physics/all")]
        public async Task<ActionResult> DeletePhysicsAll(IdInput input)
        {
            return Ok(await _systemWorkSheetLogic.DeletePhysicsAll(input));
        }

        /// <summary>
        /// 恢复删除业务数据
        /// </summary>
        /// <param name="input">Id</param>
        /// <returns></returns>
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-恢复删除业务数据", RemarkFrom.System, true)]
        [Route("/system/worksheet/delete/recovery")]
        public async Task<ActionResult> RecoveryDeletePhysics(SystemWorkSheetDeleteInput input)
        {
            return Ok(await _systemWorkSheetLogic.RecoveryDeletePhysics(input));
        }

        /// <summary>
        /// 视图获取信息
        /// </summary>
        /// <param name="input">获取所有信息</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取所有信息", RemarkFrom.System)]
        [Route("/system/worksheet/list")]
        public async Task<ActionResult> Find(SystemWorkSheetFindPagingInput input)
        {
            input.Header = Request.Headers["Authorization"];
            return Ok(await _systemWorkSheetLogic.Find(input));
        }

        /// <summary>
        /// 获取关联表业务数据默认值
        /// 1，表单编辑时，初始化读取关联字段的内容值出来，在页面上进行绑定
        /// </summary>
        /// <param name="input">获取关联表业务数据默认值</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取关联表业务数据", RemarkFrom.System)]
        [Route("/system/worksheet/correlation/default")]
        public async Task<ActionResult> FindCorrelationDefault(SystemWorkSheetFindCorrelationDefaultFieldInput input)
        {
            return Ok(await _systemWorkSheetLogic.FindCorrelationDefault(input));
        }

        /// <summary>
        /// 获取默认值是工作表类型数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取关联表业务数据", RemarkFrom.System)]
        [Route("/system/worksheet/correlation/default/worksheet")]
        public async Task<ActionResult> FindCorrelationDefaultWorkSheet(SystemWorkSheetFindCorrelationDefaultWorkSheetInput input)
        {
            return Ok(await _systemWorkSheetLogic.FindCorrelationDefaultWorkSheet(input));
        }

        /// <summary>
        /// 获取默认值是关联字段类型数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取关联表业务数据", RemarkFrom.System)]
        [Route("/system/worksheet/correlation/default/field")]
        public async Task<ActionResult> FindCorrelationDefaultField(SystemWorkSheetFindCorrelationDefaultFieldInput input)
        {
            return Ok(await _systemWorkSheetLogic.FindCorrelationDefaultField(input));
        }

        /// <summary>
        /// 获取所有关联数据
        /// 1，关联数据设计器选择默认值使用
        /// </summary>
        /// <param name="input">获取关联表业务数据</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取关联表业务数据", RemarkFrom.System)]
        [Route("/system/worksheet/correlation/filter/all")]
        public async Task<ActionResult> FindCorrelationFilterAll(SystemWorkSheetFindCorrelationFilterAllInput input)
        {
            return Ok(await _systemWorkSheetLogic.FindCorrelationFilterAll(input));
        }

        /// <summary>
        /// 弹窗选择框选择数据进行使用
        /// 1,表单里面进行选择获取数据使用
        /// </summary>
        /// <param name="input">获取关联表业务数据</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取关联表业务数据", RemarkFrom.System)]
        [Route("/system/worksheet/correlation/filter")]
        public async Task<ActionResult> FindCorrelationFilter(SystemWorkSheetFindCorrelationFilterInput input)
        {
            return Ok(await _systemWorkSheetLogic.FindCorrelationFilter(input));
        }

        /// <summary>
        /// 获取关联表业务数据
        /// 表单里面子表和关联表为列表时读取数据
        /// </summary>
        /// <param name="input">获取关联表业务数据</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取关联表业务数据", RemarkFrom.System)]
        [Route("/system/worksheet/correlation/rows")]
        public async Task<ActionResult> FindCorrelationRows(SystemWorkSheetFindCorrelationRowsInput input)
        {
            return Ok(await _systemWorkSheetLogic.FindCorrelationRows(input));
        }
        /// <summary>
        /// 查询字段值唯一
        /// </summary>
        /// <param name="input">查询字段值唯一</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-查询字段值唯一", RemarkFrom.System)]
        [Route("/system/worksheet/only")]
        public async Task<ActionResult> CheckOnly(SystemZeroCodeOnlyInput input)
        {
            return Ok(await _systemWorkSheetLogic.CheckOnly(input));
        }
        /// <summary>
        /// 复制数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-复制数据", RemarkFrom.System)]
        [Route("/system/worksheet/copy")]
        public async Task<ActionResult> Copy(SystemWorkSheetCopyInput input)
        {
            input.UserId = CurrentUser.UserId;
            input.UserCode = CurrentUser.Code;
            input.UserName = CurrentUser.Name;
            input.OrganizationName = CurrentUser.OrganizationName;
            if (CurrentUser.OrganizationId != null) input.OrganizationId = (Guid)CurrentUser.OrganizationId;
            var result = await _systemWorkSheetLogic.Copy(input);
            return Ok(result);
        }

        /// <summary>
        /// 获取左侧查询
        /// </summary>
        /// <param name="input">获取所有信息</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取所有信息", RemarkFrom.System)]
        [Route("/system/worksheet/list/filtersearch")]
        public async Task<ActionResult> FindFilterSearch(SystemWorkSheetFilterSearchInput input)
        {
            input.Header = Request.Headers["Authorization"];
            return Ok(await _systemWorkSheetLogic.FindFilterSearch(input));
        }
       
        /// <summary>
        /// 获取表尾数据
        /// </summary>
        /// <param name="input">获取所有信息</param>
        /// <returns></returns>
        [FieldFilter]
        [HttpPost]
        [CreateBy("孙泽伟")]
        [Remark("零代码-方法-列表-获取所有信息", RemarkFrom.System)]
        [Route("/system/worksheet/footer")]
        public async Task<ActionResult> FindFooter(SystemWorkSheetFindFooterInput input)
        {
            return Ok(await _systemWorkSheetLogic.FindFooter(input));
        }
        
        #endregion
    }
}